<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 * @author   howe <howe1995@163.com>
 */

namespace App\Cache;

use App\Cache\Repository\SetGroupRedis;

/**
 * 聊天室 - 缓存助手.
 */
class SocketRoom extends SetGroupRedis
{
    protected $name = 'ws:room';

    /**
     * 获取房间名.
     *
     * @param int|string $room 房间名
     * @return string
     */
    public function getRoomName($room)
    {
        return $this->getCacheKey($room);
    }

    /**
     * 获取房间中所有的用户ID.
     *
     * @param string $room 房间名
     * @return array
     */
    public function getRoomMembers(string $room)
    {
        return $this->all($room);
    }

    /**
     * 添加房间成员.
     *
     * @param string $room 房间名
     * @param string ...$member 用户ID
     * @return bool|int
     */
    public function addRoomMember(string $room, string ...$member)
    {
        return $this->add($room, ...$member);
    }

    /**
     * 删除房间成员.
     *
     * @param string $room 房间名
     * @param string ...$member 用户ID
     */
    public function delRoomMember(string $room, string ...$member): int
    {
        return $this->rem($room, ...$member);
    }

    /**
     * 删除房间.
     *
     * @param int|string $room 房间名
     */
    public function delRoom($room): int
    {
        return $this->delete($room);
    }
}
